package com.qf.fmall2202.shopcart.controller;

import com.qf.fmall2202.shopcart.entity.ShoppingCart;
import com.qf.fmall2202.shopcart.service.ShoppingCartService;
import com.qf.fmall2202.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 购物车  前端控制器
 * </p>
 *
 * @author 徐英海
 * @since 2022-11-08
 */
@CrossOrigin
@RestController
@RequestMapping("/shopcart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    public ResultVo list(Integer userId) {
        return shoppingCartService.queryList(userId);
    }

    @PostMapping("/add")
    public ResultVo addToShoppingCart(@RequestBody ShoppingCart shoppingCart) {
        return shoppingCartService.addToShoppingCart(shoppingCart);
    }

    @PutMapping("/update/{cartId}/{cartNum}")
    public ResultVo update(@PathVariable("cartId") Integer cartId, @PathVariable("cartNum") Integer cartNum) {
        return shoppingCartService.updateCartNumByCartId(cartId, cartNum);
    }

    @GetMapping("/listbycids")
    public ResultVo listbycids(@RequestParam("cids") String cids) {
        return shoppingCartService.listbycids(cids);
    }
}
